<!DOcType html>
<html lang="en">
{% load static %}
<head>
    <title>{{ SYS_TITLE }}</title>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="description" content="">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="robots" content="all,follow">
    <link rel="shortcut icon" href="{% static 'images/favicon.ico' %}" type="image/x-icon">
    <link rel="stylesheet" href="{% static 'css/bootstrap.min.css' %}">
    <link rel="stylesheet" href="{% static 'css/bundle.css' %}">
    <link rel="stylesheet" href="{% static 'css/style.min.css' %}">
</head>
<body class="bg-white h-100-vh p-t-0">
    <div class="container h-100-vh">
        <div class="row align-items-md-center h-95-vh">
            <div class="col-lg-6 d-none d-lg-block">
                <img class="img-fluid" src="{% static 'images/login.svg' %}" alt="...">
            </div>
            <div class="col-lg-4 offset-lg-1">
                <div class="d-flex align-items-center m-b-20">
                    <img src="{% static 'images/logo.png' %}" class="m-r-15" width="40" alt="">
                    <h1 class="ml-4">{{ SYS_TITLE }}</h1>
                </div>
                <form method="post" action="" class="form-validate" id="loginFrom">
                    <div class="form-group mb-5">
                        <input type="text" class="form-control form-control-lg" name="username" id="login-username" autofocus required placeholder="用户名" value="admin">
                    </div>
                    <div class="form-group mb-5">
                        <input type="password" class="form-control form-control-lg" id="login-password" name="password" required placeholder="密码">
                    </div>
                    <div class="form-group mb-5">
                        <input type="text" class="form-control form-control-lg captcha col-lg-7" id="id_captcha_1" name="captcha_1" placeholder="验证码" autocomplete="off" autocapitalize="off" spellcheck="false">
                        <img src="" class="m-l-10 captcha" alt="captcha" style="cursor:pointer">
                        <input type="hidden" class="form-control form-control-lg captcha" id="id_captcha_0" name="captcha_0" value="">
                    </div>
                    <button type="submit" class="btn btn-primary btn-lg btn-block btn-uppercase mb-5" id="login">登录</button>
                    <div class="d-flex justify-content-between align-items-center mb-5">
                        <div class="custom-control custom-checkbox">
                            <input type="checkbox" class="custom-control-input" id="check2" >
                            <label class="custom-control-label" for="check2">自动登录</label>
                        </div>
                        <div class="custom-control custom-checkbox ">
                            <input type="checkbox" class="custom-control-input" id="check1" >
                            <label class="custom-control-label" for="check1">记住密码&nbsp;&nbsp;</label>
                        </div>
                    </div>
                    {% if msg %}
                        <div class="alert alert-danger alert-dismissible" role="alert">
                            <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                            {{ msg }}
                        </div>
                    {% endif %}
                    {% csrf_token %}
                </form>
            </div>
        </div>
        <div style="text-align: center">Copyright © 2021-2022 昜丿捺. All right reserved</div>
    </div>

    <script src="{% static 'js/jquery.min.js' %}"></script>
    <script src="{% static 'js/bootstrap.min.js' %}"></script>
    <script>
        $(function(){
            /*判断上次是否勾选记住密码和自动登录*/
            const check1s = localStorage.getItem("check1");
            const check2s = localStorage.getItem("check2");
            const oldName = localStorage.getItem("userName");
            const oldPass = localStorage.getItem("passWord");
            if(check1s==="true"){
                $("#login-username").val(oldName);
                $("#login-password").val(oldPass);
                $("#check1").prop('checked',true);
            }else{
                $("#login-username").val('');
                $("#login-password").val('');
                $("#check1").prop('checked',false);
            }
            if(check2s==="true"){
                $("#check2").prop('checked',true);
                $("#loginFrom").submit();
            }else{
                $("#check2").prop('checked',false);
            }
            refresh();
            /*登录*/
            $("#login").click(function(){
                const userName = $("#login-username").val();
                const passWord = $("#login-password").val();
                /*获取当前输入的账号密码*/
                localStorage.setItem("userName",userName)
                localStorage.setItem("passWord",passWord)
                /*获取记住密码  自动登录的 checkbox的值*/
                const check1 = $("#check1").prop('checked');
                const check2 = $('#check2').prop('checked');
                localStorage.setItem("check1",check1);
                localStorage.setItem("check2",check2);
            })
            $("img.captcha").click(function (){
                refresh();
            });
        })
    </script>
    <script>
        function refresh(){
            $.getJSON("/captcha/refresh",function (data){
                $("img.captcha").attr("src",data.image_url);
                $("#id_captcha_0").attr("value",data.key);
            });
        }
    </script>

</body>
</html>
